/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React from 'react';
import { getAuthDetailList } from '@/utils/admin/menu/index';

export interface tableItem {
  id: string;
  name: string;
  phone: string;
  department: string[];
  jurisdiction: string[];
}

export interface ManagerInfo {
  id: number;
  userid: string;
  name: string;
  mobile: string;
  RoleCallback: any;
  status: number; // 激活状态: 1=已激活，2=已禁用，4=未激活，5=退出企业。
  gender: number; // 性别。0表示未定义，1表示男性，2表示女性
  email: string; // 邮箱
  avatar: string; // 头像url
  created_at: string; // 创建时间
  department_list: any;
}

export interface spanItem {}

const renderSpan = (data: any) => {
  return data.map((item: any, index: number) => (
    <span key={index + '_'}>
      {item} {data.length <= index + 1 ? '' : '，'}
    </span>
  ));
};

export const columns = (authorityRoutes: any, allAddAuth: any, handleMenuList: any) => {
  return [
    {
      title: '序号',
      dataIndex: 'id',
      align: 'center',
      search: false,
      width: 60,
    },
    {
      title: '姓名',
      dataIndex: 'name',
      align: 'center',
      search: false,
      width: 140,
    },
    {
      title: '手机号',
      dataIndex: 'mobile',
      align: 'center',
      search: false,
      width: 140,
    },
    {
      title: '部门',
      dataIndex: 'department_list',
      align: 'center',
      search: false,
      width: 360,
      ellipsis: true,
      render: (_, record: any) => renderSpan(record.department_list.map((item: any) => item.name)),
    },
    {
      title: '已授权功能',
      dataIndex: 'menu_list',
      align: 'center',
      search: false,
      width: 400,
      ellipsis: true,
      render: (_: any, record: any) => {
        const menuList = getAuthDetailList(authorityRoutes, record.menu_list.map(Number));
        return <a onClick={handleMenuList.bind(null, menuList)}>{menuList}</a>;
      },
    },
    {
      title: '操作',
      key: 'option',
      search: false,
      align: 'center',
      width: 80,
      fixed: 'right',
      render: (data: any) => {
        return <a onClick={allAddAuth.bind(null, data.id)}>权限管理</a>;
      },
    },
  ];
};
